﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SosaAnalysisModule.Data;
using SosaAnalysisModule;
using System.IO;

namespace AnalysisModuleTest
{
    [TestClass]
    public class FileReaderUnitTest
    {
        [TestMethod]
        public void testCSV1()
        {
            //setup
            SosaData sample = new SosaData();
            String path = Directory.GetCurrentDirectory();
            string token = "SosaAnalysisModule\\";
            int length = path.IndexOf(token) + token.Length;
            path = path.Substring(0, length-1) + "SosaAnalysisModuleTest\\testFinal.csv";
            sample = SOSAFileReader.CreateSosaData(path);

            //matching
            //needs to be updated
            Assert.AreEqual("1", sample.ExperimentID);
            Assert.AreEqual("1", sample.Version);
            Assert.AreEqual("test", sample.Subject);
            Assert.AreEqual("October 19 2012 (02:55 AM)", sample.Date);
            Assert.AreEqual("Unlabled 1", sample.PresentationOrder[0].Label);
            Assert.AreEqual("Unlabled 2", sample.PresentationOrder[1].Label);
            Assert.AreEqual("Unlabled 3", sample.PresentationOrder[2].Label);
            Assert.AreEqual("Unlabled 4", sample.PresentationOrder[3].Label);
            Assert.AreEqual("02:55:01.003",sample.InitialPreviewTime);
            Assert.AreEqual("02:55:07.368",sample.ExperimentStartTime);
            Assert.AreEqual("02:55:14.872", sample.SubjectActions[0].Time);
            Assert.AreEqual("02:55:16.790", sample.SubjectActions[1].Time);
            Assert.AreEqual("02:55:18.772", sample.SubjectActions[2].Time);
            Assert.AreEqual("02:55:20.644", sample.SubjectActions[3].Time);
            Assert.AreEqual("02:55:22.781", sample.SubjectActions[4].Time);
            Assert.AreEqual(-5.8313317, sample.SubjectActions[0].To.X);
            Assert.AreEqual(-5.2765894, sample.SubjectActions[0].To.Y);
            Assert.AreEqual(4.4849315, sample.SubjectActions[1].To.X);
            Assert.AreEqual(5.0192795, sample.SubjectActions[1].To.Y);
            Assert.AreEqual(-5.323082, sample.SubjectActions[2].To.X);
            Assert.AreEqual(3.1375887, sample.SubjectActions[2].To.Y);
            Assert.AreEqual(5.767389, sample.SubjectActions[3].To.X);
            Assert.AreEqual(-7.2838907, sample.SubjectActions[3].To.Y);
            Assert.AreEqual(0.48086676, sample.SubjectActions[4].To.X);
            Assert.AreEqual(-1.7801087, sample.SubjectActions[4].To.Y);

            Assert.AreEqual(-5, sample.FinalPositions[0].position.X);
            Assert.AreEqual(5, sample.FinalPositions[0].position.Y);
            Assert.AreEqual(5, sample.FinalPositions[1].position.X);
            Assert.AreEqual(-5, sample.FinalPositions[1].position.Y);
            Assert.AreEqual(5, sample.FinalPositions[2].position.X);
            Assert.AreEqual(5, sample.FinalPositions[2].position.Y);
            Assert.AreEqual(-5, sample.FinalPositions[3].position.X);
            Assert.AreEqual(-5, sample.FinalPositions[3].position.Y);

            Assert.AreEqual(13.124862, sample.Distances[0][1]);
            Assert.AreEqual(20.848635, sample.Distances[0][2]);
            Assert.AreEqual(16.759674, sample.Distances[0][3]);
            Assert.AreEqual(13.124862, sample.Distances[1][0]);
            Assert.AreEqual(7.862925, sample.Distances[1][2]);
            Assert.AreEqual(12.983067, sample.Distances[1][3]);
            Assert.AreEqual(20.848635, sample.Distances[2][0]);
            Assert.AreEqual(7.862925, sample.Distances[2][1]);
            Assert.AreEqual(17.682703, sample.Distances[2][3]);
            Assert.AreEqual(16.759674, sample.Distances[3][0]);
            Assert.AreEqual(12.983067, sample.Distances[3][1]);
            Assert.AreEqual(17.682703, sample.Distances[3][2]);
        }

    }
}
